package com.atguigu.service.ipml;

import com.atguigu.dao.BaseDao;
import com.atguigu.service.BaseService;
import com.atguigu.util.CastUtil;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;

import java.io.Serializable;
import java.util.List;
import java.util.Map;

/**
 * @Author chenxin
 * @date 2023/2/10
 * @Version 1.0
 */
public abstract class BaseServiceImpl<T> implements BaseService<T> {

    //1. 将该类变成抽象类
    //2. 在该类中添加抽象方法
    public abstract BaseDao<T> getDao();

    @Override
    public PageInfo<T> findPage(Map filters) {
        int pageNum= CastUtil.castInt(filters.get("pageNum"),1);
        int pageSize=CastUtil.castInt(filters.get("pageSize"),5);
        PageHelper.startPage(pageNum,pageSize);
        List<T> list = this.getDao().findPage(filters);
        return new PageInfo<>(list,3);
    }

    @Override
    public void insert(T t) {
        this.getDao().insert(t);
    }

    @Override
    public T getById(Serializable id) {
        return this.getDao().getById(id);
    }

    @Override
    public void update(T t) {
        this.getDao().update(t);
    }

    @Override
    public void delete(Serializable id) {
        this.getDao().delete(id);
    }
}
